package br.mikhas.util;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotSame;
import static org.junit.Assert.assertTrue;

import org.junit.Test;

public class PairTeste {

	@Test
	public final void testHashCode() {
		Pair<Integer, Integer> a = new Pair<Integer, Integer>(123, 321);
		Pair<Integer, Integer> b = new Pair<Integer, Integer>(321, 123);

		assertEquals(a.hashCode(), b.hashCode());
	}

	@Test
	public final void testPair() {
		new Pair<Integer, Integer>(null, null);
		new Pair<Integer, Integer>(321, null);
		new Pair<Integer, Integer>(null, 123);
		new Pair<Integer, Integer>(321, 123);
	}

	@Test
	public final void testContains() {
		Pair<Integer, Integer> a;

		a = new Pair<Integer, Integer>(123, 321);

		assertTrue(a.contains(123));
		assertTrue(a.contains(321));
		assertFalse(a.contains(null));

		a = new Pair<Integer, Integer>(123, null);

		assertTrue(a.contains(123));
		assertTrue(a.contains(null));
		assertFalse(a.contains(321));

		a = new Pair<Integer, Integer>(null, 321);

		assertTrue(a.contains(321));
		assertTrue(a.contains(null));
		assertFalse(a.contains(123));
	}

	@Test
	public final void testGetFirst() {
		Pair<Integer, Integer> a;
		a = new Pair<Integer, Integer>(123, 321);

		assertEquals((Object) 123, a.getFirst());
		assertNotSame(321, a.getFirst());
	}

	@Test
	public final void testGetSecond() {
		Pair<Integer, Integer> a;
		a = new Pair<Integer, Integer>(123, 321);

		assertEquals((Object) 321, a.getSecond());
		assertNotSame(123, a.getSecond());
	}

	@Test
	public final void testEqualsObject() {
		Pair<Integer, Integer> a = new Pair<Integer, Integer>(123, 321);
		Pair<Integer, Integer> b = new Pair<Integer, Integer>(321, 123);

		assertEquals(a, b);
	}

}
